package com.zwj.controller.users;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zwj.entity.Users;
import com.zwj.service.UsersService;

@Controller
public class UsersController {

	@Autowired
	private UsersService usersService;
	
	@RequestMapping(value="/s")
	public String selectUsernameAndPassword(@Param("username") String username,@Param("password") String password,Model model) {
		Users users = this.usersService.selectUsernameAndPassword(username, password);
//		users=this.usersService.selectUsername(username);
		if(users != null) {
			model.addAttribute("users",users);
			return "main.jsp";
		}else {
			return "/login.jsp";
		}
		
	}
	
	//查询所有
	@RequestMapping(value="/s1")
	public String selectall(Users users,Model model) {
		List<Users> user = this.usersService.selectall(users);
		model.addAttribute("users",user);
		return "NewFile1.jsp";
	}
	
	//依据username查询
	@RequestMapping("/update")
	public String selusername(String username,Model model) {
		Users u=this.usersService.selectUsername(username);
		model.addAttribute("users",u);
		return "houtai.jsp";
	}
	
	//修改方法
	@RequestMapping("/update1")
	public String update(Users user,Model model) {
		boolean u=this.usersService.updatePassword(user);
		if(u) {
			System.out.println("修改成功");
			return "houtai.jsp";
		}else {
			System.out.println("修改失败");
			return "NewFile2.jsp";
		}
		
	}
}
